<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta name="author" content="zhaozhenguo">
		<title>车辆类型管理</title>
		<script language="javascript" src="../script/common.js" type="text/javascript"></script>
		<script language="javascript" type="text/javascript">
			//全局变量
			var org = Common.cOrg();	//当前单位	
			var qt = {};				//数据表格对象
			var bsName = "CarSeries";
			//页面加载方法
			function load(){
				Eui.showNavigation();
				setPages(["requestlist","searchForm1"]);	
				createTableSeries()
		 		switchPage("searchForm1");
			}
			//显示、刷新表格-系列
			function createTableSeries(){
			  	var columns = [];
					columns[2] = {title:"操作",width:"20%",render:seriesFunc,align:"center",defOrder:"desc"};
					qt = new QueryTable("sel_carseries_mgnt","searchForm","datalist",columns,{
					buttons:[
						{value:" 增 加 ",actions:function(){onNew("CarSeries")}}
					]
				});
			}
			//显示、刷新表格-品牌
			function createTableBrand(){
			  	var columns = [];
					columns[2] = {title:"操作",width:"20%",render:brandFunc,align:"center",defOrder:"desc"};
					qt = new QueryTable("sel_carbrand_mgnt","searchForm","datalist",columns,{
					buttons:[
						{value:" 增 加 ",actions:function(){onNew("CarBrand")}}
					]
				});
			}
			//显示、刷新表格-型号
			function createTableModel(){
			  	var columns = [];
					columns[3] = {title:"操作",width:"20%",render:modelFunc,align:"center",defOrder:"desc"};
					qt = new QueryTable("sel_carmodel_mgnt","searchForm","datalist",columns,{
					buttons:[
						{value:" 增 加 ",actions:function(){onNew("CarModel")}}
					]
				});
			}
			function selectDate(){
				qt.showTable();
			}
			function seriesFunc(v,r){//处理数据
				return "<a href=# onclick=onEdit('"+r[2]+"')>修改</a>&nbsp;&nbsp;<a href=# onclick=onDelete('"+r[2]+"')>删除</a>"
			}
			function brandFunc(v,r){//处理数据
				return "<a href=# onclick=onEdit('"+r[2]+"')>修改</a>&nbsp;&nbsp;<a href=# onclick=onDelete('"+r[2]+"')>删除</a>"
			}
			function modelFunc(v,r){//处理数据
				return "<a href=# onclick=onEdit('"+r[3]+"')>修改</a>&nbsp;&nbsp;<a href=# onclick=onDelete('"+r[3]+"')>删除</a>"
			}
			//点击进入新增页面
			function onNew(bs){
				$("Listform").reset();
				if(bs == "CarSeries"){
					$("seriesTDD").innerHTML = "<label>系列名称</label> <input type='text' name='name' onblur=checkV(this,'',true) maxlength=20><font class='des'>*</font>";
					$("vendorTDD").innerHTML = "<label>厂&nbsp;&nbsp;&nbsp;&nbsp;商</label> <select name='vendor' onblur=checkV(this,'')><option></option></select>";
					$("brandTDD").innerHTML = "";
					$("modelTDD").innerHTML = "";
					$("titleName").innerHTML = "车辆系列信息"
					Common.initDict($("Listform").vendor,"car_vendor","请选择");
				}else if(bs == "CarBrand"){
					$("seriesTDD").innerHTML = "<label>系列名称</label> <input type='text' name='seriesName' onblur=checkV(this,'',true) maxlength=20 disabled class='readonly'><a class=orga title='选择车辆系列' href='javascript:void(0)' onclick=selcarType('CarSeries')>&nbsp;&nbsp;</a><font class='des'>*</font>";
					$("vendorTDD").innerHTML = "";
					$("brandTDD").innerHTML = "<label>品牌名称</label> <input type='text' name='name' onblur=checkV(this,'',true) maxlength=20 ><font class='des'>*</font>";
					$("modelTDD").innerHTML = "";
					$("titleName").innerHTML = "车辆品牌信息"
				}else if(bs == "CarModel"){
					$("seriesTDD").innerHTML = "";
					$("vendorTDD").innerHTML = "";
					$("brandTDD").innerHTML = "<label>品牌名称</label> <input type='text' name='brandName' onblur=checkV(this,'',true) maxlength=20 disabled class='readonly'><a class=orga title='选择车辆品牌' href='javascript:void(0)' onclick=selcarType('CarBrand')>&nbsp;&nbsp;</a><font class='des'>*</font>";
					$("modelTDD").innerHTML = "<label>型号名称</label> <input type='text' name='name' onblur=checkV(this,'',true) maxlength=20 >";
					$("titleName").innerHTML = "车辆型号信息"
				}
				switchPage('requestlist');
			}
			function selcarType(type){
				if(type == "CarSeries"){
					var v = openDialogFrame("/basic/sel_serial_brand.html?type="+type,'选择车辆系列',300,160)
				    if (v){
					    Listform.series.value = v.id;
						Listform.seriesName.value = v.name;
					}
				}else if(type == "CarBrand"){
					var v = openDialogFrame("/basic/sel_serial_brand.html?type="+type,'选择车辆品牌',300,300)
				    if (v){
					    Listform.brand.value = v.id;
						Listform.brandName.value = v.name;
					}
				}
				
			 	
			}
			//保存和修改方法
			function onSave(){
				if(!checkForm("Listform"))return;
				if(!(showQuestion("您确认保存吗?"))){
			  		return;
		 		}
				var formValue = Common.getValues("Listform");
				if(bsName == "CarSeries"){
					DWR.call("carModelService.saveCarSeries",formValue,function(){
						showInformation("保存成功!");
						switchPage('searchForm1');
						showData();
					},{blockScreen:"true"});
				}else if(bsName == "CarBrand"){
					DWR.call("carModelService.saveCarBrand",formValue,function(){
						showInformation("保存成功!");
						switchPage('searchForm1');
						showData();
					},{blockScreen:"true"});
				}else if(bsName == "CarModel"){
					DWR.call("carModelService.saveCarModel",formValue,function(){
						showInformation("保存成功!");
						switchPage('searchForm1');
						showData();
					},{blockScreen:"true"});
				}
				
			}
			function showData(){
				qt.showTable();
			}
			//进入修改明细
			function onEdit(id){
		        if (id != null){
					 DWR.call("carModelService.getCarInfo",id,bsName,function(backValue){
						onNew(bsName)
						if(bsName == "CarBrand"){
							Common.setValues("Listform",backValue.carBrand);
							$("Listform").seriesName.value = backValue.carSeries.name
						}else if(bsName == "CarModel"){
							Common.setValues("Listform",backValue.carModel);
							$("Listform").brandName.value = backValue.carBrand.name
						}else{
							Common.setValues("Listform",backValue.carSeries);
						}
					});
				}
			}
			//删除方法
			function onDelete(id){
				if(!(showQuestion("确定删除吗?"))){
					return;
				}
				DWR.call("carModelService.deleteCarInfo",id,bsName,function(){
					showInformation("删除成功!");
					showData();
					switchPage('searchForm1');
				},{blockScreen:"true"});
			}
			function showTab(id,obj){
				if(id == "CarSeries"){
					bsName = "CarSeries";
					createTableSeries()
					$("brandTd").innerHTML = "";
					$("modelTd").innerHTML = "";
				}else if(id == "CarBrand"){
					bsName = "CarBrand";
					createTableBrand()
					$("brandTd").innerHTML = "<label>品牌名称</label> <input type='text' name='brandName' maxlength=30 >";
					$("modelTd").innerHTML = "";
				}else if(id == "CarModel"){
					bsName = "CarModel";
					createTableModel();
					$("brandTd").innerHTML = "<label>品牌名称</label> <input type='text' name='brandName' maxlength=30 >";
					$("modelTd").innerHTML = "<label>型号名称</label> <input type='text' name='modelName' maxlength=30 >";
				}
				switchPage("searchForm1");
				$("tab_series").className = "treeTab";
    			$("tab_brand").className = "treeTab";
				$("tab_model").className = "treeTab";
    			if (typeof obj == "string") obj = $(obj)
    			obj.className = "treeTabc";
			}
			function backShow(){
				switchPage("searchForm1");
			}
		</script>
	</head>
	<body onload="load()">
		<!--页面导航-->
		<div class="nav"><div id="nav">&nbsp;</div></div>
	<div id="cardBillDiv">
	<div id="detailForm" style="width:95%">
		<div id='group_a' align="left">
			<a href='#' onclick="showTab('CarSeries',this);return false;" onfocus="this.blur()" tabindex="-1" id="tab_series" class="treeTabc">系列维护</a>
			<a href='#'  onclick="showTab('CarBrand',this);return false;" onfocus="this.blur()" tabindex="-1" id="tab_brand" class="treeTab">品牌维护</a>
			<a href='#'  onclick="showTab('CarModel',this);return false;" onfocus="this.blur()" tabindex="-1" id="tab_model" class="treeTab">型号维护</a>
		</div>
		<div id="searchForm1" class="searchForm" class="width100">
			<form id="searchForm" name="searchForm">
				<input type="hidden" name="organization">
				<table cellSpacing=0 cellPadding=6 width="100%" border=0>
					<tr>
						<td><label>系列名称</label> <input type="text" name="seriesName" onblur="checkV(this,'')" maxlength=30></td>
							<td id="brandTd"></td>
							<td id="modelTd"></td>
						<td><button type="button" onclick="selectDate()" >查   询</button></td>
					</tr>
				</table>
			</form>
			<div id="datalist"></div>
		</div>
		
		<div id="requestlist" style="display:none;" class="detview">
			<div class="form">
					<div class="formTitle">
						<span id="titleName"></span>
					</div>
				<form id="Listform" name="Listform">
					<input type="hidden" name="id">
					<input type="hidden" name="series">
					<input type="hidden" name="brand">
					<input type="hidden" name="model">
					<table cellSpacing=0 cellPadding=1 width="100%" border=0>
						<tr>
							<td id="seriesTDD"></td>
							<td id="brandTDD"></td>
							<td id="modelTDD"></td>
							<td id="vendorTDD"></td>
						</tr>
					</table>
				</form>
			</div>
			<p align="center">
				<button type='button' id='saveBtn' name='saveBtn' onclick='onSave()'>保   存</button>&nbsp;&nbsp;&nbsp;<button type='button' onclick='backShow()' >返   回</button>
			</p>
		</div>
	</div>
	</div>
	</body>
</html>